/**
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY. See the GNU General Public License for more details. Copyright (C) 2011 CellObject.net
 */
package net.cellobject.sqlitexmlbrowser.sqlitebrowser.schema;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class SchemaContentProvider implements ITreeContentProvider {
	@Override
	public Object[] getChildren(final Object parentElement) {
		if (parentElement instanceof SchemaTreeNode) {
			final SchemaTreeNode schemaTreeNode = (SchemaTreeNode)parentElement;
			return schemaTreeNode.getChildren().toArray();
		}
		return new Object[0];
	}

	@Override
	public Object getParent(final Object element) {
		return element;
	}

	@Override
	public boolean hasChildren(final Object element) {
		if (element instanceof SchemaTreeNode) {
			final SchemaTreeNode schemaTreeNode = (SchemaTreeNode)element;
			return schemaTreeNode.getChildCount() > 0;
		}
		return false;
	}

	@Override
	public Object[] getElements(final Object inputElement) {
		return getChildren(inputElement);
	}

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
	}
}
